package com.ap.core.business.message.response.translators.impl;

import com.ap.core.business.message.domain.translators.BindingMetaData;
import com.ap.core.business.message.response.translators.ResponseMetaData;
import com.ap.core.business.message.response.translators.ResponseTranslator;
import com.ap.core.business.message.response.translators.listener.ResponseListener;
import com.ap.core.cxf.jaxb.common.ResponseStatusType;
import com.ap.core.cxf.jaxb.common.ResponseWithIntentType;
import com.ap.core.message.managertp.info.ResponseRTPMessageInfo;
import com.ap.core.message.managertp.info.SubmitRTPMessageInfo;

/**
 * User: Ranjit.Singh
 * implementation class for {@link ResponseTranslator} to populate {@link ResponseWithIntentType}  in response object
 */
public class SubmitRTPResponseTranslator implements ResponseTranslator<SubmitRTPMessageInfo, ResponseRTPMessageInfo> {

    /**
     * {@inheritDoc}
     */
    @Override
    public void populateResponse(SubmitRTPMessageInfo request, ResponseRTPMessageInfo response, BindingMetaData bindingMetaData, ResponseMetaData responseMetaData, ResponseListener responseListener) {
        ResponseWithIntentType responseWithIntentType = new ResponseWithIntentType();
        responseWithIntentType.setMobAppIntent(responseMetaData.getMobileAppIntentId());
        responseWithIntentType.setApTransactionId(responseMetaData.getApTransaction().getApTransactionId());
        responseWithIntentType.setApTRId(responseMetaData.getApTransaction().getApTransactionRetrievalId());
        responseWithIntentType.setBRN(responseMetaData.getBasketReferenceNumber());
        responseWithIntentType.setRTPId(request.getRTPSummary().getTxIdentification().getRTPId());
        responseWithIntentType.setReconId(responseMetaData.getReconciliationId());

        ResponseStatusType responseStatusType = new ResponseStatusType();
        responseStatusType.setResponseCode(responseMetaData.getValidationStatus().getResponseCode());

        responseWithIntentType.setResponseStatus(responseStatusType);

        response.setResponseInfo(responseWithIntentType);

        responseListener.onMessageResponse(response);

    }

}
